package com.ali.resource.ControllerPage;

import com.ali.resource.CompoentPage.RdsComponent;
import com.ali.resource.CompoentPage.RedisComponent;
import com.ali.resource.MapPage.rds.RdsMap;
import com.ali.resource.MapPage.redis.RedisMap;
import com.ali.resource.ServicePage.RdsService;
import com.ali.resource.ServicePage.RedisService;
import com.ali.resource.ShareTools.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@Tag(name = "rds接口文档" , description = "rds资源信息查询")
@RestController
@RequestMapping("/redis")
public class RedisController {

    @Autowired
    private RedisService redisService;

    @Autowired
    private RedisComponent redisComponent;

    @Operation(summary = "getList",description = "获取redis列表")
    @Parameter(name = "bool", description = "是否下载至xlsx")
    @GetMapping("/getList")
    public Result getRdsList(@RequestParam(required = true,defaultValue = "false") String bool
            , @RequestParam(required = false) String instanceIdPrefix
            , @RequestParam(required = false) String instanceNamePrefix) throws Exception {

        ArrayList<RedisMap> redisMaps = redisService.getRdsList(bool, instanceIdPrefix, instanceNamePrefix);

        if (bool.equals("true")) {
            redisService.getXlsx(redisMaps);
        }

        return Result.builder().total(redisMaps.size()).code(200).data(redisMaps).build();
    }

}
